const utils = require('common.js');
//const utils = require('/storage/emulated/0/脚本/common.js');

var storage = storages.create("init");
var vedios= parseInt(storage.get("火刷视界文章"));

var appname = "火刷视界"
var cs= storage.get(appname+"初始");
var sx= storage.get(appname+"上限");

if(cs>=sx){
    toastLog(appname+"达到阅读上限");
    exit();
}else{
    storage.put(appname+"初始",cs+vedios);
    log(storage.get(appname+"初始"));
}

initParam={
    appName:"火刷视界",
    totalNewsReaded : 0,//已经阅读的新闻条数
    totalNewsOneTime : 50,//一次性阅读多少条新闻
    loopTimeToFindNews : 5,//找了多少次新闻找不到会退出
    indexBtnText: "", //其他页面挑到首页的按钮文字，重要！
    indexFlagText:"关注",
    readallText:"展开全文",

    tanchuang:"imgClose",
    timeAwardText : "领取",//时段奖励关键字

    lastVedioText:"",//上一次新闻标题
    totalVedioReaded : 0,//已经阅读的新闻条数
    totalVedioOneTime : 50,//一次性阅读多少条新闻
    loopTimeToFindVedio : 20,//找了多少次新闻找不到会退出
    stanchuang:"弹窗id",
    indexBtnTexts: "首页", //其他页面挑到首页的按钮文字，重要！
    indexFlagTexts : "iv_like",//首页特有的标志id，重要！

    news:0,
    vedio:vedios,
    hdsj:12,
    newssx:"首页",
    vediosx:"首页",
};

utils.wakeUp(); 
utils.clears();
utils.launch(initParam.appName);
sleep(4000);
utils.UITextBoundsClick("我知道了");
utils.UITextBoundsClick("首页");
utils.UITextBoundsClick("关闭");
var flag=false;

for(i=1;i<=initParam.vedio;i++){
    var flag=false;
    var xx=0;
    sleep(1000);
    utils.UITextBoundsClick("我知道了");
    swipe(device.width / 2, device.height/1.2,  device.width / 2, device.height-device.height/1.05, 1500);
    toastLog("观看第"+i+"个视频");
    readvedios();
    var gx1 = text("去领取").findOnce()
    if(gx1){
        toastLog("领取奖励");
        click(gx1.bounds().centerX(),gx1.bounds().centerY());
        sleep(55000);
        back();
        sleep(2000)
        utils.UIIDBoundsClick("tt_video_ad_close");
    }
    var gx1 = text("继续赚贡献值").findOnce()
    if(gx1){
        toastLog("领取奖励");
        click(gx1.bounds().centerX(),gx1.bounds().centerY());
        sleep(55000);
        back();
        sleep(2000)
        utils.UIIDBoundsClick("tt_video_ad_close");
    }
    if(text("首页").findOnce()){
        sleep(500)
    }else{
        back();
        sleep(1000)
    }
};
utils.UITextBoundsClick("我的");
sleep(3000)
for(var i=0;i<=30;i++){
    sleep(1000)
    var gx1 = text("去阅读").findOnce()
    if(gx1){
        toastLog("领取奖励");
        click(gx1.bounds().centerX(),gx1.bounds().centerY());
        sleep(5000);
        var wz = id("news_title").findOnce()
        if(wz){
            toastLog("点击文章")
            click(wz.bounds().centerX(),wz.bounds().centerY());
            sleep(2000);
            for(var j=0;j<4;j++){
                utils.UIIDBoundsClick("tt_insert_dislike_icon_img");
                swipe(device.width / 2, device.height/1.2,  device.width / 2, device.height-device.height/1.05, 1500);
                sleep(5000);
            }
        }
        utils.UIIDBoundsClick("backBtn");
        sleep(2000)
        utils.UIIDBoundsClick("iv_back");
        sleep(3000)
    }
    var gx1 = text("立即领取").findOnce()
    if(gx1){
        toastLog("领取奖励");
        click(gx1.bounds().centerX(),gx1.bounds().centerY());
        sleep(55000);
        back();
        sleep(2000)
        utils.UIIDBoundsClick("tt_video_ad_close");
        sleep(4000)
    }
    var gx1 = text("继续赚贡献值").findOnce()
    if(gx1){
        toastLog("领取奖励");
        click(gx1.bounds().centerX(),gx1.bounds().centerY());
        sleep(55000);
        back();
        sleep(2000)
        utils.UIIDBoundsClick("tt_video_ad_close");
        sleep(5000)
    }
    var gx1 = text("立即领取").findOnce(1)
    if(gx1){
        toastLog("领取奖励");
        click(gx1.bounds().centerX(),gx1.bounds().centerY());
        sleep(55000);
        back();
        sleep(2000)
        utils.UIIDBoundsClick("tt_video_ad_close");
        sleep(5000)
    }
    var gx1 = text("继续观看").findOnce()
    if(gx1){
        toastLog("领取奖励");
        click(gx1.bounds().centerX(),gx1.bounds().centerY());
        sleep(55000);
        back();
        sleep(2000)
        utils.UIIDBoundsClick("tt_video_ad_close");
        sleep(5000)
    }
    var gx1 = text("立即领取").findOnce(2)
    if(gx1){
        toastLog("领取奖励");
        click(gx1.bounds().centerX(),gx1.bounds().centerY());
        sleep(55000);
        back();
        sleep(2000)
        utils.UIIDBoundsClick("tt_video_ad_close");
        sleep(5000)
    }
    var gx1 = text("继续赚门派知名度").findOnce()
    if(gx1){
        toastLog("领取奖励");
        click(gx1.bounds().centerX(),gx1.bounds().centerY());
        sleep(55000);
        back();
        sleep(2000)
        utils.UIIDBoundsClick("tt_video_ad_close");
        sleep(5000)
    }

    var gx1 = text("领取完成").findOnce()
    if(gx1){
        toastLog("领取奖励");
        click(gx1.bounds().centerX(),gx1.bounds().centerY());
        sleep(55000);
        back();
        sleep(2000)
        utils.UIIDBoundsClick("tt_video_ad_close");
        sleep(3000)
    }
    if(descContains("下载").findOnce()){
        var gb = className("android.widget.ImageView").depth(5).findOnce()
        if(gb){
            click(gb.bounds().centerX(),gb.bounds().centerY());
            log("关闭")
            sleep(1500);
        }
    }
    if(textContains("下载").findOnce()){
        var gb = className("android.widget.ImageView").depth(5).findOnce()
        if(gb){
            click(gb.bounds().centerX(),gb.bounds().centerY());
            log("关闭")
            sleep(1500);
        }
    }
    if(textContains("点击打开").findOnce()){
        var gb = className("android.widget.ImageView").depth(5).findOnce()
        if(gb){
            click(gb.bounds().centerX(),gb.bounds().centerY());
            log("关闭")
            sleep(1500);
        }
    }
    utils.UIIDBoundsClick("backBtn");
    utils.UIIDBoundsClick("iv_back");
}
//阅读新闻
function readvedios(seconds){

        //滑动阅读新闻
        for(var i = 0 ;i < 1 ;i++){
            var tt = random(10000,20000);
            sleep(tt);
        }

}


